package com.duoshu.grj.sosoliuda.upload;

import java.util.HashMap;
import java.util.Map;

/**
 * 短视频上传管理类
 */

public class SnapVideoUploadManager {

    private static SnapVideoUploadManager instance = null;

    public static SnapVideoUploadManager getInstance(){
        if(instance == null) {
            instance = new SnapVideoUploadManager();
        }
        return instance;
    }

    private Map<String, SnapVideoUploadApi> uploadClientMap = new HashMap<>();

    public void cancel(String uploadTaskId){

        uploadClientMap.get(uploadTaskId).cancel();
        uploadClientMap.remove(uploadTaskId);
    }

    public void pause(String uploadTaskId){

        uploadClientMap.get(uploadTaskId).pause();
    }

    public void resume(String uploadTaskId){

        uploadClientMap.get(uploadTaskId).resume();
    }

    public void addUploadTask(String uploadTaskId, SnapVideoUploadApi uploadTask, SnapVideoUploadCallback callback) {

        uploadClientMap.put(uploadTaskId, uploadTask);
        uploadTask.upload(callback);

    }

    public void releaseUploadTask(String uploadTaskId){
        SnapVideoUploadApi uploadTask = uploadClientMap.remove(uploadTaskId);
        uploadTask.release();

    }

    public SnapVideoUploadApi getUploadTask(String taskId){
        return uploadClientMap.get(taskId);
    }


}
